package mysql

import (
	"doctor-medicine-system/doctorrpc/doctorrpc"
	"gorm.io/gorm"
)

type Medicine struct {
	gorm.Model
	Title    string `gorm:"type:varchar(30);not null;comment:'药品名称'"`
	Address  string `gorm:"type:varchar(300);not null;comment:'生产地'"`
	Desc     string `gorm:"type:varchar(500);not null;comment:'适应症'"`
	Action   string `gorm:"type:varchar(500);not null;comment:'注意事项'"`
	DoctorId int64  `gorm:"type:int(11);not null;comment:'医生id'"`
}

func (m *Medicine) MedicineAdd(db *gorm.DB) error {
	return db.Debug().Create(m).Error
}

func MedicineList(db *gorm.DB, id int64, list []*doctorrpc.MedicineList) []*doctorrpc.MedicineList {
	db.Debug().Model(&Medicine{}).
		Select("medicines.id as medicine_id,medicines.*,doctors.doctor_name").
		Joins("left join doctors on doctors.id = medicines.doctor_id").
		Where("medicines.doctor_id = ?", id).Find(&list)
	return list
}
